describe("App.AuthoriseTransaction",function(){
    var transactionObject;
    beforeEach(function(){
       transactionObject = App.AuthoriseTransaction.create();
    });

    it("isNotApprovedorPending--returns TE",function(){
        transactionObject.set('transactionStatus','TE');
        expect(transactionObject.get('transactionStatus')).toBe('TE');
        expect(transactionObject.get('isNotApprovedorPending')).toBe(true);
    });

    it("isApproved--returns TY",function(){
        transactionObject.set('transactionStatus','TY');
        expect(transactionObject.get('transactionStatus')).toBe('TY');
        expect(transactionObject.get('isApproved')).toBe(true);
    });


    it("isNotApprovedorPending--returns TR",function(){
        transactionObject.set('transactionStatus','TR');
        expect(transactionObject.get('transactionStatus')).toBe('TR');
        expect(transactionObject.get('isNotApprovedorPending')).toBe(true);
    });

    it("canConfirm",function(){
        transactionObject.set('transactionStatus','TN');
        expect(transactionObject.get('transactionStatus')).toBe('TN');
        expect(transactionObject.get('canConfirm')).toBe(true);
    });

    it("canDecline--return true if Status is TN",function(){
        transactionObject.set('transactionStatus','TN');
        expect(transactionObject.get('transactionStatus')).toBe('TN');
        expect(transactionObject.get('canDecline')).toBe(true);
    });

    it("canDecline--return true if Status is TE",function(){
        transactionObject.set('transactionStatus','TE');
        expect(transactionObject.get('transactionStatus')).toBe('TE');
        expect(transactionObject.get('canDecline')).toBe(false);
    });

    it("transactionStatus",function(){
       var transactionStatus='transactionStatus';
       var authorizeObject = App.AuthoriseTransaction.create({
            "status":transactionStatus
        });

        expect(authorizeObject.get('transactionStatus')).toEqual(transactionStatus);

    });

    it("transactionStatusDescription",function(){

        var authorizeObject = App.AuthoriseTransaction.create({
            "status":"TN"
        });
        var transactionStatusDescription = BreezeUtils.getAuthoriseTransactionStatusDescription(authorizeObject.status);
        expect(authorizeObject.get('transactionStatusDescription')).toEqual(transactionStatusDescription);

    });

    it("transactionTypeDescription",function(){

        var authorizeObject = App.AuthoriseTransaction.create({
            "type":"15"
        });
        var transactionTypeDescription = BreezeUtils.getPaymentTypeDescription(authorizeObject.type);
        expect(authorizeObject.get('transactionTypeDescription')).toEqual('Unknown');

    });

    it("destinationAccountNumber returns empty",function(){
       transactionObject.set('toAccountNumber',null);
       transactionObject.set('payeeName',null);

       expect(transactionObject.get('destinationAccountNumber')).toBe('');
    });


    it("destinationAccountNumber returns PayeeName",function(){
        transactionObject.set('payeeName','Telecomm');
        expect(transactionObject.get('destinationAccountNumber')).toBe('Telecomm');
    });

    it("destinationAccountNumber returns AccountNumber",function(){
        transactionObject.set('toAccountNumber','021156789');
        expect(transactionObject.get('destinationAccountNumber')).toBe('021156789');
    });

    it("isCrossTransfer--fromAccountCurrencyCode not equal toCurrencyCode",function(){
        transactionObject.set('toAccountCurrencyCode','IDR');
        transactionObject.set('fromAccountCurrencyCode','USD');
        var cc = transactionObject.get('toAccountCurrencyCode');
        expect(transactionObject.get('toAccountCurrencyCode')).toEqual(cc);
        expect(transactionObject.get('isCrossTransfer')).toBe(true);
    });

    it("isCrossTransfer--toCurrencyCode is null",function(){
        var cc = transactionObject.get('toAccountCurrencyCode');
        expect(Ember.none(cc)).toBe(true);
        expect(transactionObject.get('toAccountCurrencyCode')).toEqual(null);
        expect(transactionObject.get('isCrossTransfer')).toBe(false);
    });

    it("exchangeCurrencyCode--returns fromAccountCurrencyCode",function(){
        transactionObject.set('toAccountCurrencyCode','IDR');
        transactionObject.set('currencyCode','IDR');
        expect(transactionObject.get('exchangeCurrencyCode')).toBe(transactionObject.get('fromAccountCurrencyCode'));
    });

    it("exchangeCurrencyCode--returns toAccountCurrencyCode",function(){
        transactionObject.set('toAccountCurrencyCode','USD');
        transactionObject.set('currencyCode','IDR');
        expect(transactionObject.get('exchangeCurrencyCode')).toBe(transactionObject.get('toAccountCurrencyCode'));
    });

    it("displayableObjectInList",function(){
        var authorizeObj ={
            'id':"22",
            'title':"Own Account Transfer",
            'secondLabel':"20130513000100",
            'isNegative':true,
            'isText':true,
            'text':"Pending"
        };

        transactionObject.set('key', authorizeObj.id);
        transactionObject.set('transactionTypeDescription', authorizeObj.title);
        transactionObject.set('etacReqId', authorizeObj.secondLabel);
        transactionObject.set('isNotApprovedorPending', authorizeObj.isNegative);
        transactionObject.set('isText',authorizeObj.isText);
        transactionObject.set('transactionStatusDescription',authorizeObj.text);

        expect(JSON.stringify(transactionObject.get('displayableObjectInList'))).toBe(JSON.stringify(authorizeObj));
    });

    it("displayableObject",function(){
        var t= App.i18n.getTranslations();
        var responseObject ={
            "type": "Own Account Transfer",
            "status": "Pending",
            "from": "02100014891",
            "to": "02105081619",
            "amount": 1.00,
            "currencyCode":"IDR",
            "transferDate": "2013-05-13T18:54:47.497+0800",
            "etacReqId": "20130513000100",
            fromAccountCurrencyCode: 'IDR',
            toAccountCurrencyCode: 'IDR'
        };

        transactionObject.set('transactionTypeDescription',responseObject.type);
        transactionObject.set('transactionStatusDescription',responseObject.status);
        transactionObject.set('sourceAccountNumber',responseObject.from);
        transactionObject.set('destinationAccountNumber',responseObject.to);
        transactionObject.set('amount',responseObject.amount);
        transactionObject.set('currencyCode',responseObject.currencyCode);
        transactionObject.set('transferDate',responseObject.transferDate);
        transactionObject.set('etacReqId',responseObject.etacReqId);
        transactionObject.set('fromAccountCurrencyCode', responseObject.fromAccountCurrencyCode);
        transactionObject.set('toAccountCurrencyCode', responseObject.toAccountCurrencyCode);

        var expectedOutput =
                    [
                        {key:t.get('see.type'), value:transactionObject.transactionTypeDescription},
                        {key:t.get('authorise.eTACStatus'), value:transactionObject.transactionStatusDescription},
                        {key:t.get('see.from'),value:transactionObject.sourceAccountNumber+', '+transactionObject.fromAccountCurrencyCode},
                        {key:t.get('see.to'),value:transactionObject.destinationAccountNumber+', '+transactionObject.toAccountCurrencyCode},
                        {
                            key:t.get('see.amount'),
                            value:{currencyCode:'IDR', amount:transactionObject.amount},
                            isAmount: true
                        },
                        {key:t.get('see.date'), value:BreezeDateUtils.formatDateStyleEEEEddMMMMyyyy(transactionObject.transferDate)},
                        {key:t.get('move.etacReferenceNo'), value:transactionObject.etacReqId}
                    ];

        expect(JSON.stringify(transactionObject.get('displayableObject'))).toBe(JSON.stringify(expectedOutput));

    });

    it("displayableObjectForSummary",function(){
        var t= App.i18n.getTranslations();
        var responseObject = {
            "type": "Own Account Transfer",
            "from": "02100014891",
            "to": "02105081619",
            "amount": 1.00,
            "currencyCode":"IDR",
            "transferDate": "2013-05-13T18:54:47.497+0800",
            fromAccountCurrencyCode: 'IDR',
            toAccountCurrencyCode: 'IDR'
        };

        transactionObject.set('transactionTypeDescription',responseObject.type);
        transactionObject.set('sourceAccountNumber',responseObject.from);
        transactionObject.set('destinationAccountNumber',responseObject.to);
        transactionObject.set('amount',responseObject.amount);
        transactionObject.set('currencyCode',responseObject.currencyCode);
        transactionObject.set('transferDate',responseObject.transferDate);
        transactionObject.set('fromAccountCurrencyCode', responseObject.fromAccountCurrencyCode);
        transactionObject.set('toAccountCurrencyCode', responseObject.toAccountCurrencyCode);

        var expectedOutput =
            [
                {key:t.get('see.type'), value:transactionObject.transactionTypeDescription},
                {key:t.get('see.from'),value:transactionObject.sourceAccountNumber+', '+transactionObject.fromAccountCurrencyCode},
                {key:t.get('see.to'),value:transactionObject.destinationAccountNumber+', '+transactionObject.toAccountCurrencyCode},
                {
                    key:t.get('see.amount'),
                    value:{currencyCode:'IDR', amount:transactionObject.amount},
                    isAmount: true
                },
                {key:t.get('see.date'), value:BreezeDateUtils.formatDateStyleEEEEddMMMMyyyy(transactionObject.transferDate)},
                {key:t.get('move.etacReferenceNo'), value:transactionObject.etacReqId}
            ];

        expect(JSON.stringify(transactionObject.get('displayableObjectForSummary'))).toBe(JSON.stringify(expectedOutput));

    });


});